<template>
    <div class="icons">
        <swiper :options="swiperOption">
            <swiper-slide v-for="page in pages" :key="page[0].id">
                <div class="icon-img" v-for="item in page" :key="item.id">
                    <img :src="item.imgUrl" alt="">
                    <p>{{item.desc}}</p>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {}
    }
  },
  computed: {
    pages () {
      let pages = []
      this.list.forEach((item, index) => {
        let page = Math.floor((index / 8))
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
@import '~@/assets/styles/mixins.styl'
    .icons
        height 0
        overflow hidden
        padding-bottom 50%
        .icon-img
            float left
            width 25%
            height 0
            padding-bottom 25%
            img
                width 70%
                display block
                margin .14rem auto
            p
                text-align center
                padding .2rem
                line-height .44rem
                margin-top -.32rem
                ellipsis()

</style>
